import router from '@/router'
export default {
    setUserToken(state,user){ //保存用户token 以及用户信息
       state.user=user
       state.token=user.token
    },
    setNavTreeData(state,navTreeData){//保存左侧菜单导航栏数据
        state.navTreeData=navTreeData
        console.log(navTreeData)
        //动态将所有菜单路由添加到路由表中
        function addRouter(routerList){
                routerList.forEach((navRouter) => {
                    if(!navRouter.child){
                        console.log('1')
                        router.addRoute('views', {
                            path: `${navRouter.menu_path}`,
                            name: `${navRouter.router_name}`,
                            component: () => import(`@/${navRouter.menu_components}`)
                          })
                                              
                    }else{
                        addRouter(navRouter.child)
                    }
                });
        }
        addRouter(state.navTreeData)
       
    },
    clearUserInfo(state){
        sessionStorage.removeItem('user');
        state.user={}
        state.token=''
        state.navTreeData=[]
    }
}